var Bmob = require('../../../utils/bmob.js');
var common = require('../../../utils/common.js');
var app = getApp()
Page({
    data: {
        choose: ['空闲中','预约中','不可预约'],
        index: 0,
        username: null
    },

    onLoad: function () {
      var that = this;
      var username = app.globalData.username;
      that.setData({
        username: username
      });
    },

    formSubmit: function (event) {
        var that = this;
        var username = that.data.username;
        var equip_id = event.detail.value.equip_id;
        var description = event.detail.value.description;
        var state = that.data.index;
        console.log(username + equip_id + description + state);
        // var state = that.data.index;
        if (equip_id != "" && username != "" && description != "") {
          wx.request({
            url: 'https://car.shiliangproject.cn/equipment/createequip',
            data: {
              username: username,
              equip_id: equip_id,
              description: description,
            },
            // 请求头
            header: {
              'Content-Type': 'application/x-www-form-urlencoded'
            },
            method: "POST",
            success: function (res) {
              console.log(res.data);
              if (res.data['res'] == 1) {
                common.showTip('创建成功！');
                setTimeout(function () {
                  wx.redirectTo({
                    url: '../equipmanage/equipmanage'
                  });
                }, 2000);
              } else {
                common.showTip('创建失败！', 'loading');
              }
            }
          })
        } else {
          wx.showLoading({
            title: '车位信息错误！',
          });
          setTimeout(function () {
            wx.hideLoading();
          }, 1500);
        }
    },

    bindPickerChange: function (e) {
      this.setData({
        index: e.detail.value
      })
    },

    /**
  * 生命周期函数--监听页面初次渲染完成
  */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

})